from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
from mooc.db.database import init_db
from mooc.api.v1.api import api_router
from mooc.core.config import settings

app = FastAPI(
    title="ExamService",
    description="题库小程序服务端API",
    version="1.0.0"
)

# CORS设置
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 初始化数据库
init_db()

app.include_router(api_router, prefix=settings.API_V1_STR)

@app.get("/")
async def root():
    return {"message": "Welcome to ExamService API"}

if __name__ == '__main__':
    uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True, workers=1)